/**
 *@author: chenyoulong 
 *@Title:PersonBean.java
 *@date 2012-9-28 下午3:10:47 
 *@Description:TODO
 */
package com.hj.tools.xml;

import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

/**
 *@ClassName:PersonBean
 *@author: chenyoulong  Email: chen.youlong@payeco.com
 *@date :2012-9-28 下午3:10:47
 *@Description:TODO 
 */
@XStreamAlias("person")
public class PersonBean {
	@XStreamAlias("firstName")
	private String firstName;
	@XStreamAlias("lastName")
	private String lastName;

	@XStreamAlias("telphone")
	private PhoneNumber tel;
	@XStreamAlias("faxphone")
	private PhoneNumber fax;

	//测试一个标签下有多个同名标签
	@XStreamAlias("friends")
	private Friends friend;

	//测试一个标签下循环对象
	@XStreamAlias("pets")
	private Pets pet;

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public PhoneNumber getTel() {
		return tel;
	}

	public void setTel(PhoneNumber tel) {
		this.tel = tel;
	}

	public PhoneNumber getFax() {
		return fax;
	}

	public void setFax(PhoneNumber fax) {
		this.fax = fax;
	}

	public Friends getFriend() {
		return friend;
	}

	public void setFriend(Friends friend) {
		this.friend = friend;
	}

	public Pets getPet() {
		return pet;
	}

	public void setPet(Pets pet) {
		this.pet = pet;
	}

	@XStreamAlias("phoneNumber")
	public static class PhoneNumber {
		@XStreamAlias("code")
		private int code;
		@XStreamAlias("number")
		private String number;

		public int getCode() {
			return code;
		}

		public void setCode(int code) {
			this.code = code;
		}

		public String getNumber() {
			return number;
		}

		public void setNumber(String number) {
			this.number = number;
		}

	}

	/**
	 * 用Xstream注解的方式实现：一个标签下有多个同名标签 
	 *@ClassName:Friends
	 *@author: chenyoulong  Email: chen.youlong@payeco.com
	 *@date :2012-9-28 下午4:32:24
	 *@Description:TODO 5个name 中国，美国，俄罗斯，英国，法国
	 *http://blog.csdn.net/menhuanxiyou/article/details/5426765
	 */
	public static class Friends {
		@XStreamImplicit(itemFieldName = "name")
		//itemFieldName定义重复字段的名称，
		/*<friends>								<friends>
			<name>A1</name>							<String>A1</String>
			<name>A2</name>    如果没有，则会变成	=====>		<String>A1</String>
			<name>A3</name>							<String>A1</String>
		</friends>								</friends>
		*/
		private List<String> name;

		public List<String> getName() {
			return name;
		}

		public void setName(List<String> name) {
			this.name = name;
		}
	}

	//测试同一标签下循环某一对象
	public static class Animal {
		@XStreamAlias("name")
		private String name;
		@XStreamAlias("age")
		private int age;

		public Animal(String name, int age) {
			this.name = name;
			this.age = age;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public int getAge() {
			return age;
		}

		public void setAge(int age) {
			this.age = age;
		}
	}

	/**
	 * 测试同一标签下循环某一对象
	 *@ClassName:Pets
	 *@author: chenyoulong  Email: chen.youlong@payeco.com
	 *@date :2012-9-28 下午6:26:01
	 *@Description:TODO
	 */
	public static class Pets {
		@XStreamImplicit(itemFieldName = "pet")
		private List<Animal> animalList;

		public List<Animal> getAnimalList() {
			return animalList;
		}

		public void setAnimalList(List<Animal> animalList) {
			this.animalList = animalList;
		}

	}
}
